﻿#region

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion

namespace Pob.GameObjects.PowerUps.General
{
    public abstract class PowerUp : GameObject
    {
        #region Fields

        internal Circle HitCircle;

        private readonly PowerUpCreator _myCreator;

        private Vector2 _origin;

        #endregion

        #region Constructors and Destructors

        protected PowerUp(Game game, string assetName, Vector2 position, float sizeFactor, PowerUpCreator creator)
            : base(game, assetName, position, sizeFactor, Color.White)
        {
            _myCreator = creator;
        }

        #endregion

        #region Public Methods and Operators

        public abstract void ActivateEffect(Player owner, GameTime gameTime);

        public abstract void DeactivateEffect();

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Begin();
            SpriteBatch.Draw(Textur, Position, null, Color.White, 0, _origin, SizeFactor, SpriteEffects.None, 0f);
            SpriteBatch.End();
        }

        public void Store(Player owner)
        {
            Settings settings = SettingsManager.CurrentInstance.Settings;

            switch (owner.Side)
            {
                case Side.Left:

                    Position = new Vector2(settings.Width / 2f - 100, 40);
                    break;

                case Side.Right:

                    Position = new Vector2(settings.Width / 2f + 100, 40);
                    break;
            }

            _myCreator.ClearDisplayedPowerUp();
        }

        #endregion

        #region Methods

        protected override void LoadContent()
        {
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            Textur = Game.Content.Load<Texture2D>(AssetName);

            _origin = new Vector2(Textur.Width / 2f, Textur.Height / 2f);

            HitCircle = new Circle(Position, Textur.Width / 2f);
        }

        #endregion
    }
}